x = int(input())

x1 = x
d = x1%10
c = x1//10%10
b = x1//100%10
a = x1//1000

ma=0

count=0
for i in range(1,x+1):
    if x%i==0:
        count+=1
if count ==2:
    c10=x
    if c10>ma:
        ma=c10
count=0
k1=b*100+c*10+d
for i in range(1,k1+1):
    if k1%i==0:
        count+=1
if count ==2:
    c1=k1
    if c1>ma:
        ma=c1
        
count=0
k2=a*100+b*10+c
for i in range(1,k2+1):
    if k2%i==0:
        count+=1
if count ==2:
    c2=k2
    if c2>ma:
        ma=c2
    
count=0
k3=c*10+d
for i in range(1,k3+1):
    if k3%i==0:
        count+=1
if count ==2:
    c3=k3
    if c3>ma:
        ma=c3

count=0
k4=b*10+c
for i in range(1,k4+1):
    if k4%i==0:
        count+=1
if count ==2:
    c4=k4
    if c4>ma:
        ma=c4

count=0
k5=a*10+b
for i in range(1,k5+1):
    if k5%i==0:
        count+=1
if count ==2:
    c5=k5
    if c5>ma:
        ma=c5
    
count=0
k6=a
for i in range(1,k6+1):
    if k6%i==0:
        count+=1
if count ==2:
    c6=k6
    if c6>ma:
        ma=c6
    
count=0
k7=b
for i in range(1,k7+1):
    if k7%i==0:
        count+=1
if count ==2:
    c7=k7
    if c7>ma:
        ma=c7
    
count=0
k8=c
for i in range(1,k8+1):
    if k8%i==0:
        count+=1
if count ==2:
    c8=k8
    if c8>ma:
        ma=c8

count=0
k9=d
for i in range(1,k9+1):
    if k9%i==0:
        count+=1
if count ==2:
    c9=k9
    if c9>ma:
        ma=c9
if len(str(x))!=4:
    ma=0
if x<0:
    ma=0
print(ma)
